<!DOCTYPE html><html lang="zh-CN" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0,viewport-fit=cover"><title>React模拟移入title提示 | 破破的QQ空间</title><meta name="author" content="破破"><meta name="copyright" content="破破"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta name="description" content="React 模拟移入 title 提示1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495">
<meta property="og:type" content="article">
<meta property="og:title" content="React模拟移入title提示">
<meta property="og:url" content="https://leiboy.gitee.io/blog/2023/03/18/React%E6%A8%A1%E6%8B%9F%E7%A7%BB%E5%85%A5title%E6%8F%90%E7%A4%BA/index.html">
<meta property="og:site_name" content="破破的QQ空间">
<meta property="og:description" content="React 模拟移入 title 提示1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://leiboy.gitee.io/blog/2023/03/18/React%E6%A8%A1%E6%8B%9F%E7%A7%BB%E5%85%A5title%E6%8F%90%E7%A4%BA/react-logo.png">
<meta property="article:published_time" content="2023-03-18T14:58:49.000Z">
<meta property="article:modified_time" content="2024-07-01T14:13:29.123Z">
<meta property="article:author" content="破破">
<meta property="article:tag" content="react">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://leiboy.gitee.io/blog/2023/03/18/React%E6%A8%A1%E6%8B%9F%E7%A7%BB%E5%85%A5title%E6%8F%90%E7%A4%BA/react-logo.png"><link rel="shortcut icon" href="/blog/img/favicon.png"><link rel="canonical" href="https://leiboy.gitee.io/blog/2023/03/18/React%E6%A8%A1%E6%8B%9F%E7%A7%BB%E5%85%A5title%E6%8F%90%E7%A4%BA/index.html"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="preconnect" href="//busuanzi.ibruce.info"/><link rel="stylesheet" href="/blog/css/index.css?v=4.14.0-b3"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@6.5.1/css/all.min.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fancyapps/ui@5.0.35/dist/fancybox/fancybox.min.css" media="print" onload="this.media='all'"><script>(()=>{
      const saveToLocal = {
        set: (key, value, ttl) => {
          if (ttl === 0) return
          const now = Date.now()
          const expiry = now + ttl * 86400000
          const item = {
            value,
            expiry
          }
          localStorage.setItem(key, JSON.stringify(item))
        },
      
        get: key => {
          const itemStr = localStorage.getItem(key)
      
          if (!itemStr) {
            return undefined
          }
          const item = JSON.parse(itemStr)
          const now = Date.now()
      
          if (now > item.expiry) {
            localStorage.removeItem(key)
            return undefined
          }
          return item.value
        }
      }
      
      window.btf = {
        saveToLocal: saveToLocal,
        getScript: (url, attr = {}) => new Promise((resolve, reject) => {
          const script = document.createElement('script')
          script.src = url
          script.async = true
          script.onerror = reject
          script.onload = script.onreadystatechange = function() {
            const loadState = this.readyState
            if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
            script.onload = script.onreadystatechange = null
            resolve()
          }

          Object.keys(attr).forEach(key => {
            script.setAttribute(key, attr[key])
          })

          document.head.appendChild(script)
        }),

        getCSS: (url, id = false) => new Promise((resolve, reject) => {
          const link = document.createElement('link')
          link.rel = 'stylesheet'
          link.href = url
          if (id) link.id = id
          link.onerror = reject
          link.onload = link.onreadystatechange = function() {
            const loadState = this.readyState
            if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
            link.onload = link.onreadystatechange = null
            resolve()
          }
          document.head.appendChild(link)
        }),

        addGlobalFn: (key, fn, name = false, parent = window) => {
          const pjaxEnable = false
          if (!pjaxEnable && key.startsWith('pjax')) return

          const globalFn = parent.globalFn || {}
          const keyObj = globalFn[key] || {}
    
          if (name && keyObj[name]) return
    
          name = name || Object.keys(keyObj).length
          keyObj[name] = fn
          globalFn[key] = keyObj
          parent.globalFn = globalFn
        }
      }
    
      const activateDarkMode = () => {
        document.documentElement.setAttribute('data-theme', 'dark')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
        }
      }
      const activateLightMode = () => {
        document.documentElement.setAttribute('data-theme', 'light')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
        }
      }

      btf.activateDarkMode = activateDarkMode
      btf.activateLightMode = activateLightMode
      
      const t = saveToLocal.get('theme')
    
        if (t === 'dark') activateDarkMode()
        else if (t === 'light') activateLightMode()
      
      const asideStatus = saveToLocal.get('aside-status')
      if (asideStatus !== undefined) {
        if (asideStatus === 'hide') {
          document.documentElement.classList.add('hide-aside')
        } else {
          document.documentElement.classList.remove('hide-aside')
        }
      }
    
      const detectApple = () => {
        if(/iPad|iPhone|iPod|Macintosh/.test(navigator.userAgent)){
          document.documentElement.classList.add('apple')
        }
      }
      detectApple()
    })()</script><script>const GLOBAL_CONFIG = {
  root: '/blog/',
  algolia: undefined,
  localSearch: undefined,
  translate: undefined,
  noticeOutdate: undefined,
  highlight: {"plugin":"highlight.js","highlightCopy":true,"highlightLang":true,"highlightHeightLimit":false,"highlightFullpage":true,"highlightMacStyle":false},
  copy: {
    success: '复制成功',
    error: '复制错误',
    noSupport: '浏览器不支持'
  },
  relativeDate: {
    homepage: false,
    post: false
  },
  runtime: '',
  dateSuffix: {
    just: '刚刚',
    min: '分钟前',
    hour: '小时前',
    day: '天前',
    month: '个月前'
  },
  copyright: undefined,
  lightbox: 'fancybox',
  Snackbar: undefined,
  infinitegrid: {
    js: 'https://cdn.jsdelivr.net/npm/@egjs/infinitegrid@4.11.1/dist/infinitegrid.min.js',
    buttonText: '加载更多'
  },
  isPhotoFigcaption: false,
  islazyload: false,
  isAnchor: false,
  percent: {
    toc: true,
    rightside: false,
  },
  autoDarkmode: false
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = {
  title: 'React模拟移入title提示',
  isPost: true,
  isHome: false,
  isHighlightShrink: false,
  isToc: true,
  postUpdate: '2024-07-01 22:13:29'
}</script><meta name="generator" content="Hexo 6.3.0"></head><body><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="avatar-img is-center"><img src="https://i.loli.net/2021/02/24/5O1day2nriDzjSu.png" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="sidebar-site-data site-data is-center"><a href="/blog/archives/"><div class="headline">文章</div><div class="length-num">10</div></a><a href="/blog/tags/"><div class="headline">标签</div><div class="length-num">7</div></a><a href="/blog/categories/"><div class="headline">分类</div><div class="length-num">2</div></a></div><hr class="custom-hr"/></div></div><div class="post" id="body-wrap"><header class="post-bg" id="page-header" style="background-image: url('/blog/2023/03/18/React%E6%A8%A1%E6%8B%9F%E7%A7%BB%E5%85%A5title%E6%8F%90%E7%A4%BA/react-logo.png')"><nav id="nav"><span id="blog-info"><a href="/blog/" title="破破的QQ空间"><span class="site-name">破破的QQ空间</span></a></span><div id="menus"><div id="toggle-menu"><span class="site-page"><i class="fas fa-bars fa-fw"></i></span></div></div></nav><div id="post-info"><h1 class="post-title">React模拟移入title提示</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">发表于</span><time class="post-meta-date-created" datetime="2023-03-18T14:58:49.000Z" title="发表于 2023-03-18 22:58:49">2023-03-18</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">更新于</span><time class="post-meta-date-updated" datetime="2024-07-01T14:13:29.123Z" title="更新于 2024-07-01 22:13:29">2024-07-01</time></span><span class="post-meta-categories"><span class="post-meta-separator">|</span><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/blog/categories/react/">react</a></span></div><div class="meta-secondline"><span class="post-meta-separator">|</span><span class="post-meta-pv-cv" id="" data-flag-title="React模拟移入title提示"><i class="far fa-eye fa-fw post-meta-icon"></i><span class="post-meta-label">阅读量:</span><span id="busuanzi_value_page_pv"><i class="fa-solid fa-spinner fa-spin"></i></span></span></div></div></div></header><main class="layout" id="content-inner"><div id="post"><article class="post-content" id="article-container"><h1 id="React-模拟移入-title-提示"><a href="#React-模拟移入-title-提示" class="headerlink" title="React 模拟移入 title 提示"></a>React 模拟移入 title 提示</h1><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line"><span class="comment">// 引入必要的包和组件</span></span><br><span class="line"><span class="keyword">import</span> <span class="title class_">React</span>, &#123; memo, useState, useRef, <span class="title class_">MouseEvent</span> &#125; <span class="keyword">from</span> <span class="string">&quot;react&quot;</span>;</span><br><span class="line"><span class="keyword">import</span> <span class="string">&quot;./index.scss&quot;</span>;</span><br><span class="line"></span><br><span class="line"><span class="comment">// 定义组件的属性类型</span></span><br><span class="line">interface <span class="title class_">IMouseBubble</span> &#123;</span><br><span class="line">	<span class="attr">content</span>: string | <span class="title class_">React</span>.<span class="property">ReactNode</span>; <span class="comment">// 气泡中的内容</span></span><br><span class="line">	<span class="attr">children</span>: string | <span class="title class_">React</span>.<span class="property">ReactNode</span>; <span class="comment">// 用户悬停的内容</span></span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="comment">// 定义 MouseBubble 组件</span></span><br><span class="line"><span class="keyword">const</span> index = <span class="title function_">memo</span>(<span class="function">(<span class="params">props: IMouseBubble</span>) =&gt;</span> &#123;</span><br><span class="line">	<span class="comment">// 组件接收两个参数 children 和 content，分别表示触发气泡提示框的区域和提示框中要展示的内容。</span></span><br><span class="line">	<span class="keyword">const</span> &#123; children, content &#125; = props;</span><br><span class="line"></span><br><span class="line">	<span class="comment">// 定义组件的状态变量</span></span><br><span class="line">	<span class="keyword">const</span> [visible, setVisible] = <span class="title function_">useState</span>(<span class="literal">false</span>); <span class="comment">// 气泡是否可见</span></span><br><span class="line">	<span class="keyword">const</span> [position, setPosition] = <span class="title function_">useState</span>(&#123;</span><br><span class="line">		<span class="attr">top</span>: <span class="number">0</span>,</span><br><span class="line">		<span class="attr">left</span>: <span class="number">0</span>,</span><br><span class="line">	&#125;); <span class="comment">// 气泡的位置</span></span><br><span class="line"></span><br><span class="line">	<span class="comment">// 定义组件的引用变量</span></span><br><span class="line">	<span class="keyword">const</span> wrapperRef = useRef&lt;<span class="title class_">HTMLDivElement</span>&gt;(<span class="literal">null</span>); <span class="comment">// 外层元素的引用</span></span><br><span class="line">	<span class="keyword">const</span> bubbleRef = useRef&lt;<span class="title class_">HTMLDivElement</span>&gt;(<span class="literal">null</span>); <span class="comment">// 气泡元素的引用</span></span><br><span class="line"></span><br><span class="line">	<span class="comment">// 计算气泡的位置，首先获取触发气泡提示框的区域的位置和尺寸信息，再获取提示框自身的位置和尺寸信息。根据鼠标事件的坐标和这些信息，计算出气泡提示框应该出现的位置，并返回该位置。</span></span><br><span class="line">	<span class="keyword">const</span> <span class="title function_">getOffset</span> = (<span class="params">e: MouseEvent</span>) =&gt; &#123;</span><br><span class="line">		<span class="keyword">const</span> event = e || <span class="variable language_">window</span>.<span class="property">event</span>;</span><br><span class="line">		<span class="keyword">const</span> &#123; x, y, width, height &#125; = (</span><br><span class="line">			wrapperRef.<span class="property">current</span> <span class="keyword">as</span> <span class="title class_">HTMLDivElement</span></span><br><span class="line">		).<span class="title function_">getBoundingClientRect</span>();</span><br><span class="line">		<span class="keyword">const</span> bubbleObj = (</span><br><span class="line">			bubbleRef.<span class="property">current</span> <span class="keyword">as</span> <span class="title class_">HTMLDivElement</span></span><br><span class="line">		).<span class="title function_">getBoundingClientRect</span>();</span><br><span class="line"></span><br><span class="line">		<span class="keyword">let</span> _x = event.<span class="property">clientX</span>;</span><br><span class="line">		<span class="keyword">let</span> _y = event.<span class="property">clientY</span>;</span><br><span class="line">		<span class="keyword">const</span> winW = <span class="variable language_">window</span>.<span class="property">innerWidth</span>;</span><br><span class="line"></span><br><span class="line">		<span class="comment">// 如果鼠标移出了外层元素，则隐藏气泡</span></span><br><span class="line">		<span class="keyword">if</span> (_x &gt; x + width || _x &lt; x || _y &gt; y + height || _y &lt; y) &#123;</span><br><span class="line">			<span class="title function_">setVisible</span>(<span class="literal">false</span>);</span><br><span class="line">		&#125;</span><br><span class="line"></span><br><span class="line">		<span class="keyword">let</span> bubbleX = _x - <span class="number">30</span>;</span><br><span class="line">		<span class="keyword">let</span> bubbleY = _y - bubbleObj.<span class="property">height</span> - <span class="number">18</span>;</span><br><span class="line">		<span class="keyword">if</span> (bubbleX &lt; <span class="number">0</span>) &#123;</span><br><span class="line">			bubbleX = <span class="number">0</span>;</span><br><span class="line">		&#125;</span><br><span class="line">		<span class="keyword">if</span> (bubbleX + bubbleObj.<span class="property">width</span> &gt; winW) &#123;</span><br><span class="line">			bubbleX = _x - bubbleObj.<span class="property">width</span> + <span class="number">30</span>;</span><br><span class="line">		&#125;</span><br><span class="line">		<span class="keyword">if</span> (bubbleY &lt; <span class="number">0</span>) &#123;</span><br><span class="line">			bubbleY = _y + <span class="number">30</span>;</span><br><span class="line">		&#125;</span><br><span class="line">		<span class="keyword">return</span> &#123; <span class="attr">x</span>: bubbleX, <span class="attr">y</span>: bubbleY &#125;;</span><br><span class="line">	&#125;;</span><br><span class="line"></span><br><span class="line">	<span class="comment">// 处理鼠标移动事件</span></span><br><span class="line">	<span class="comment">// 当鼠标移入触发区域时，函数调用 setVisible 方法将 visible 状态设置为 true，然后调用 getOffset 方法计算气泡提示框的位置，并将位置信息更新到 position 状态中。当鼠标移出触发区域时，函数调用 setVisible 方法将 visible 状态设置为 false，从而隐藏气泡提示框。</span></span><br><span class="line">	<span class="keyword">const</span> <span class="title function_">handleMouseMove</span> = (<span class="params">e: MouseEvent</span>) =&gt; &#123;</span><br><span class="line">		<span class="title function_">setVisible</span>(<span class="literal">true</span>);</span><br><span class="line"></span><br><span class="line">		<span class="comment">// 计算气泡位置</span></span><br><span class="line">		<span class="keyword">const</span> &#123; x, y &#125; = <span class="title function_">getOffset</span>(e);</span><br><span class="line"></span><br><span class="line">		<span class="comment">// 更新气泡位置</span></span><br><span class="line">		<span class="title function_">setPosition</span>(&#123; <span class="attr">left</span>: x, <span class="attr">top</span>: y &#125;);</span><br><span class="line">	&#125;;</span><br><span class="line"></span><br><span class="line">	<span class="comment">// 处理鼠标离开事件</span></span><br><span class="line">	<span class="keyword">const</span> <span class="title function_">handleMouseLeave</span> = (<span class="params"></span>) =&gt; &#123;</span><br><span class="line">		<span class="title function_">setVisible</span>(<span class="literal">false</span>);</span><br><span class="line">	&#125;;</span><br><span class="line"></span><br><span class="line">	<span class="keyword">return</span> (</span><br><span class="line">		<span class="language-xml"><span class="tag">&lt;<span class="name">div</span></span></span></span><br><span class="line"><span class="tag"><span class="language-xml">			<span class="attr">className</span>=<span class="string">&quot;mouse_bubble_wrapper&quot;</span></span></span></span><br><span class="line"><span class="tag"><span class="language-xml">			<span class="attr">onMouseMove</span>=<span class="string">&#123;handleMouseMove&#125;</span></span></span></span><br><span class="line"><span class="tag"><span class="language-xml">			<span class="attr">onMouseLeave</span>=<span class="string">&#123;handleMouseLeave&#125;</span></span></span></span><br><span class="line"><span class="tag"><span class="language-xml">			<span class="attr">ref</span>=<span class="string">&#123;wrapperRef&#125;</span></span></span></span><br><span class="line"><span class="tag"><span class="language-xml">		&gt;</span></span></span><br><span class="line"><span class="language-xml">			&#123;children&#125;</span></span><br><span class="line"><span class="language-xml">			<span class="tag">&lt;<span class="name">div</span></span></span></span><br><span class="line"><span class="tag"><span class="language-xml">				<span class="attr">className</span>=<span class="string">&quot;bubble_wrapper&quot;</span></span></span></span><br><span class="line"><span class="tag"><span class="language-xml">				<span class="attr">ref</span>=<span class="string">&#123;bubbleRef&#125;</span></span></span></span><br><span class="line"><span class="tag"><span class="language-xml">				<span class="attr">style</span>=<span class="string">&#123;&#123;</span></span></span></span><br><span class="line"><span class="tag"><span class="language-xml">					<span class="attr">left:</span> `$&#123;<span class="attr">position.left</span>&#125;<span class="attr">px</span>`,</span></span></span><br><span class="line"><span class="tag"><span class="language-xml">					<span class="attr">top:</span> `$&#123;<span class="attr">position.top</span>&#125;<span class="attr">px</span>`,</span></span></span><br><span class="line"><span class="tag"><span class="language-xml">					<span class="attr">visibility:</span> `$&#123;<span class="attr">visible</span> ? &quot;<span class="attr">visible</span>&quot; <span class="attr">:</span> &quot;<span class="attr">hidden</span>&quot;&#125;`,</span></span></span><br><span class="line"><span class="tag"><span class="language-xml">				&#125;&#125;</span></span></span><br><span class="line"><span class="tag"><span class="language-xml">			&gt;</span></span></span><br><span class="line"><span class="language-xml">				&#123;typeof content === &quot;string&quot; ? (</span></span><br><span class="line"><span class="language-xml">					<span class="tag">&lt;<span class="name">div</span> <span class="attr">className</span>=<span class="string">&quot;bubble_content&quot;</span>&gt;</span>&#123;content&#125;<span class="tag">&lt;/<span class="name">div</span>&gt;</span></span></span><br><span class="line"><span class="language-xml">				) : (</span></span><br><span class="line"><span class="language-xml">					content</span></span><br><span class="line"><span class="language-xml">				)&#125;</span></span><br><span class="line"><span class="language-xml">			<span class="tag">&lt;/<span class="name">div</span>&gt;</span></span></span><br><span class="line"><span class="language-xml">		<span class="tag">&lt;/<span class="name">div</span>&gt;</span></span></span><br><span class="line">	);</span><br><span class="line">&#125;);</span><br><span class="line"></span><br><span class="line"><span class="keyword">export</span> <span class="keyword">default</span> index;</span><br><span class="line"></span><br></pre></td></tr></table></figure>
</article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta"><i class="fas fa-circle-user fa-fw"></i>文章作者: </span><span class="post-copyright-info"><a href="https://leiboy.gitee.io/blog">破破</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta"><i class="fas fa-square-arrow-up-right fa-fw"></i>文章链接: </span><span class="post-copyright-info"><a href="https://leiboy.gitee.io/blog/2023/03/18/React%E6%A8%A1%E6%8B%9F%E7%A7%BB%E5%85%A5title%E6%8F%90%E7%A4%BA/">https://leiboy.gitee.io/blog/2023/03/18/React%E6%A8%A1%E6%8B%9F%E7%A7%BB%E5%85%A5title%E6%8F%90%E7%A4%BA/</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta"><i class="fas fa-circle-exclamation fa-fw"></i>版权声明: </span><span class="post-copyright-info">本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank">CC BY-NC-SA 4.0</a> 许可协议。转载请注明来自 <a href="https://leiboy.gitee.io/blog" target="_blank">破破的QQ空间</a>！</span></div></div><div class="tag_share"><div class="post-meta__tag-list"><a class="post-meta__tags" href="/blog/tags/react/">react</a></div><div class="post_share"><div class="social-share" data-image="/blog/2023/03/18/React%E6%A8%A1%E6%8B%9F%E7%A7%BB%E5%85%A5title%E6%8F%90%E7%A4%BA/react-logo.png" data-sites="facebook,twitter,wechat,weibo,qq"></div><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1.1.3/sharejs/dist/css/share.min.css" media="print" onload="this.media='all'"><script src="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1.1.3/sharejs/dist/js/social-share.min.js" defer></script></div></div><nav class="pagination-post" id="pagination"><div class="next-post pull-full"><a href="/blog/2023/03/08/React%E9%AB%98%E9%98%B6%E7%BB%84%E4%BB%B6%E6%9C%89%E5%93%AA%E4%BA%9B%E4%BC%98%E7%82%B9%E5%92%8C%E7%BC%BA%E7%82%B9/" title="React高阶组件有哪些优点和缺点"><img class="cover" src="/blog/2023/03/08/React%E9%AB%98%E9%98%B6%E7%BB%84%E4%BB%B6%E6%9C%89%E5%93%AA%E4%BA%9B%E4%BC%98%E7%82%B9%E5%92%8C%E7%BC%BA%E7%82%B9/react-logo.png" onerror="onerror=null;src='/blog/img/404.jpg'" alt="cover of next post"><div class="pagination-info"><div class="label">下一篇</div><div class="next_info">React高阶组件有哪些优点和缺点</div></div></a></div></nav><div class="relatedPosts"><div class="headline"><i class="fas fa-thumbs-up fa-fw"></i><span>相关推荐</span></div><div class="relatedPosts-list"><div><a href="/blog/2022/04/02/React%E4%B8%AD%E7%9A%84%E5%8A%A8%E6%80%81%E8%A1%A8%E5%8D%95%E5%AE%9E%E7%8E%B0/" title="React中的动态表单实现"><img class="cover" src="/blog/2022/04/02/React%E4%B8%AD%E7%9A%84%E5%8A%A8%E6%80%81%E8%A1%A8%E5%8D%95%E5%AE%9E%E7%8E%B0/react-logo.png" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2022-04-02</div><div class="title">React中的动态表单实现</div></div></a></div><div><a href="/blog/2022/04/07/react%E5%AE%9E%E7%94%A8%E5%BA%93%EF%BC%88%E8%BD%AC%E8%BD%BD%EF%BC%89/" title="react实用库（转载）"><img class="cover" src="/blog/2022/04/07/react%E5%AE%9E%E7%94%A8%E5%BA%93%EF%BC%88%E8%BD%AC%E8%BD%BD%EF%BC%89/react-logo.png" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2022-04-07</div><div class="title">react实用库（转载）</div></div></a></div><div><a href="/blog/2022/08/02/useContext%E6%A8%A1%E6%8B%9Fredux/" title="useContext模拟redux"><img class="cover" src="/blog/2022/08/02/useContext%E6%A8%A1%E6%8B%9Fredux/react-logo.png" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2022-08-02</div><div class="title">useContext模拟redux</div></div></a></div></div></div></div><div class="aside-content" id="aside-content"><div class="card-widget card-info"><div class="is-center"><div class="avatar-img"><img src="https://i.loli.net/2021/02/24/5O1day2nriDzjSu.png" onerror="this.onerror=null;this.src='/blog/img/friend_404.gif'" alt="avatar"/></div><div class="author-info__name">破破</div><div class="author-info__description"></div></div><div class="card-info-data site-data is-center"><a href="/blog/archives/"><div class="headline">文章</div><div class="length-num">10</div></a><a href="/blog/tags/"><div class="headline">标签</div><div class="length-num">7</div></a><a href="/blog/categories/"><div class="headline">分类</div><div class="length-num">2</div></a></div><a id="card-info-btn" target="_blank" rel="noopener" href="https://github.com/xxxxxx"><i class="fab fa-github"></i><span>Follow Me</span></a></div><div class="card-widget card-announcement"><div class="item-headline"><i class="fas fa-bullhorn fa-shake"></i><span>公告</span></div><div class="announcement_content">This is my Blog</div></div><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="item-headline"><i class="fas fa-stream"></i><span>目录</span><span class="toc-percentage"></span></div><div class="toc-content"><ol class="toc"><li class="toc-item toc-level-1"><a class="toc-link" href="#React-%E6%A8%A1%E6%8B%9F%E7%A7%BB%E5%85%A5-title-%E6%8F%90%E7%A4%BA"><span class="toc-number">1.</span> <span class="toc-text">React 模拟移入 title 提示</span></a></li></ol></div></div><div class="card-widget card-recent-post"><div class="item-headline"><i class="fas fa-history"></i><span>最新文章</span></div><div class="aside-list"><div class="aside-list-item"><a class="thumbnail" href="/blog/2023/03/18/React%E6%A8%A1%E6%8B%9F%E7%A7%BB%E5%85%A5title%E6%8F%90%E7%A4%BA/" title="React模拟移入title提示"><img src="/blog/2023/03/18/React%E6%A8%A1%E6%8B%9F%E7%A7%BB%E5%85%A5title%E6%8F%90%E7%A4%BA/react-logo.png" onerror="this.onerror=null;this.src='/blog/img/404.jpg'" alt="React模拟移入title提示"/></a><div class="content"><a class="title" href="/blog/2023/03/18/React%E6%A8%A1%E6%8B%9F%E7%A7%BB%E5%85%A5title%E6%8F%90%E7%A4%BA/" title="React模拟移入title提示">React模拟移入title提示</a><time datetime="2023-03-18T14:58:49.000Z" title="发表于 2023-03-18 22:58:49">2023-03-18</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/blog/2023/03/08/React%E9%AB%98%E9%98%B6%E7%BB%84%E4%BB%B6%E6%9C%89%E5%93%AA%E4%BA%9B%E4%BC%98%E7%82%B9%E5%92%8C%E7%BC%BA%E7%82%B9/" title="React高阶组件有哪些优点和缺点"><img src="/blog/2023/03/08/React%E9%AB%98%E9%98%B6%E7%BB%84%E4%BB%B6%E6%9C%89%E5%93%AA%E4%BA%9B%E4%BC%98%E7%82%B9%E5%92%8C%E7%BC%BA%E7%82%B9/react-logo.png" onerror="this.onerror=null;this.src='/blog/img/404.jpg'" alt="React高阶组件有哪些优点和缺点"/></a><div class="content"><a class="title" href="/blog/2023/03/08/React%E9%AB%98%E9%98%B6%E7%BB%84%E4%BB%B6%E6%9C%89%E5%93%AA%E4%BA%9B%E4%BC%98%E7%82%B9%E5%92%8C%E7%BC%BA%E7%82%B9/" title="React高阶组件有哪些优点和缺点">React高阶组件有哪些优点和缺点</a><time datetime="2023-03-08T14:58:49.000Z" title="发表于 2023-03-08 22:58:49">2023-03-08</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/blog/2022/08/02/useContext%E6%A8%A1%E6%8B%9Fredux/" title="useContext模拟redux"><img src="/blog/2022/08/02/useContext%E6%A8%A1%E6%8B%9Fredux/react-logo.png" onerror="this.onerror=null;this.src='/blog/img/404.jpg'" alt="useContext模拟redux"/></a><div class="content"><a class="title" href="/blog/2022/08/02/useContext%E6%A8%A1%E6%8B%9Fredux/" title="useContext模拟redux">useContext模拟redux</a><time datetime="2022-08-02T14:58:49.000Z" title="发表于 2022-08-02 22:58:49">2022-08-02</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/blog/2022/07/13/%E5%B0%8F%E7%A8%8B%E5%BA%8F%E9%9D%A2%E8%AF%95%E9%A2%98/" title="小程序面试题"><img src="/blog/2022/07/13/%E5%B0%8F%E7%A8%8B%E5%BA%8F%E9%9D%A2%E8%AF%95%E9%A2%98/%E5%B0%8F%E7%A8%8B%E5%BA%8F%E5%9B%BE%E6%A0%87.jpeg" onerror="this.onerror=null;this.src='/blog/img/404.jpg'" alt="小程序面试题"/></a><div class="content"><a class="title" href="/blog/2022/07/13/%E5%B0%8F%E7%A8%8B%E5%BA%8F%E9%9D%A2%E8%AF%95%E9%A2%98/" title="小程序面试题">小程序面试题</a><time datetime="2022-07-13T15:39:09.000Z" title="发表于 2022-07-13 23:39:09">2022-07-13</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/blog/2022/07/10/HTML%E5%92%8CCSS%E9%9D%A2%E8%AF%95%E9%A2%98/" title="HTML和CSS面试题"><img src="/blog/2022/07/10/HTML%E5%92%8CCSS%E9%9D%A2%E8%AF%95%E9%A2%98/csslogo.png" onerror="this.onerror=null;this.src='/blog/img/404.jpg'" alt="HTML和CSS面试题"/></a><div class="content"><a class="title" href="/blog/2022/07/10/HTML%E5%92%8CCSS%E9%9D%A2%E8%AF%95%E9%A2%98/" title="HTML和CSS面试题">HTML和CSS面试题</a><time datetime="2022-07-10T14:22:28.000Z" title="发表于 2022-07-10 22:22:28">2022-07-10</time></div></div></div></div></div></div></main><footer id="footer"><div id="footer-wrap"><div class="copyright">&copy;2020 - 2024 By 破破</div><div class="framework-info"><span>框架 </span><a target="_blank" rel="noopener" href="https://hexo.io">Hexo</a><span class="footer-separator">|</span><span>主题 </span><a target="_blank" rel="noopener" href="https://github.com/jerryc127/hexo-theme-butterfly">Butterfly</a></div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="阅读模式"><i class="fas fa-book-open"></i></button><button id="darkmode" type="button" title="浅色和深色模式转换"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="单栏和双栏切换"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside-config" type="button" title="设置"><i class="fas fa-cog fa-spin"></i></button><button class="close" id="mobile-toc-button" type="button" title="目录"><i class="fas fa-list-ul"></i></button><button id="go-up" type="button" title="回到顶部"><span class="scroll-percent"></span><i class="fas fa-arrow-up"></i></button></div></div><div><script src="/blog/js/utils.js?v=4.14.0-b3"></script><script src="/blog/js/main.js?v=4.14.0-b3"></script><script src="https://cdn.jsdelivr.net/npm/@fancyapps/ui@5.0.35/dist/fancybox/fancybox.umd.min.js"></script><div class="js-pjax"><script>(() => {
  const runMermaid = (ele) => {
    window.loadMermaid = true
    const theme = document.documentElement.getAttribute('data-theme') === 'dark' ? 'dark' : 'default'

    Array.from(ele).forEach((item, index) => {
      const mermaidSrc = item.firstElementChild
      const mermaidThemeConfig = '%%{init:{ \'theme\':\'' + theme + '\'}}%%\n'
      const mermaidID = 'mermaid-' + index
      const mermaidDefinition = mermaidThemeConfig + mermaidSrc.textContent

      const renderFn = mermaid.render(mermaidID, mermaidDefinition)

      const renderV10 = () => {
        renderFn.then(({svg}) => {
          mermaidSrc.insertAdjacentHTML('afterend', svg)
        })
      }

      const renderV9 = svg => {
        mermaidSrc.insertAdjacentHTML('afterend', svg)
      }

      typeof renderFn === 'string' ? renderV9(renderFn) : renderV10()
    })
  }

  const codeToMermaid = () => {
    const codeMermaidEle = document.querySelectorAll('pre > code.mermaid')
    if (codeMermaidEle.length === 0) return
    
    codeMermaidEle.forEach(ele => {
      const newEle = document.createElement('div')
      newEle.className = 'mermaid-wrap'
      newEle.innerHTML = `<pre class="mermaid-src" hidden>${ele.textContent}</pre>`
      ele.parentNode.replaceWith(newEle)
    })
  }

  const loadMermaid = () => {
    if (false) codeToMermaid()
    const $mermaid = document.querySelectorAll('#article-container .mermaid-wrap')
    if ($mermaid.length === 0) return

    const runMermaidFn = () => runMermaid($mermaid)
    btf.addGlobalFn('themeChange', runMermaidFn, 'mermaid')
    window.loadMermaid ? runMermaidFn() : btf.getScript('https://cdn.jsdelivr.net/npm/mermaid@10.9.0/dist/mermaid.min.js').then(runMermaidFn)
  }
  
  btf.addGlobalFn('encrypt', loadMermaid, 'mermaid')
  window.pjax ? loadMermaid() : document.addEventListener('DOMContentLoaded', loadMermaid)
})()</script></div><script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script></div></body></html>